import React from 'react';
import { ChildA } from './ChildA';
import { ChildB } from './ChildB';

export class App extends React.Component {
  constructor() {
    super();
    this.state = {
      msg: '',
    };
  }

  // 消息传递函数
  setMsg = (msg) => {
    console.log('子组件B准备传递给A的数据', msg);
    this.setState({
      msg: msg,
    });
  };

  render() {
    return (
      <div>
        <h1>父组件</h1>
        <ChildA msg={this.state.msg} />
        <ChildB setMsg={this.setMsg} />
      </div>
    );
  }
}
